#include <Lotus.h>
#include <MyGUI/MyGUI.h>

using namespace Lotus;

class DummyState: public IGameState
{
public:
	DummyState()
	{
		sceneManager=GraphicManager::getInstance().getOgreRoot()->createSceneManager(Ogre::ST_GENERIC);
	}
	void onEnter()
	{
		Game::getInstance().log()<<"Enter dummy state";
		setActiveCamera(sceneManager->createCamera("Hohoho"));
		Game::getInstance().ActivateEditorSignal();
	}
	void onLeave()
	{
		Game::getInstance().log()<<"Leave dummy state";
		delete this;
	}
	void update(Ogre::Real timeSinceLastFrame)
	{
	}
};

class TestObject: public MapObject
{
public:
	virtual ~TestObject()
	{}
protected:
	virtual void onCreate()
	{
		setNode(getMap()->getSceneManager()->getRootSceneNode()->createChildSceneNode());
		Game::getInstance().log()<<"Test Object created";
	}
	virtual void onChildAttached(MapObject* child)
	{
		Game::getInstance().log()<<"Child added";
	}
	virtual void onLoad(const Lotus::SaveData& data){};
	virtual void onSave(Lotus::SaveData& data) const{};
};

PluggableProduct<TestObject> entry("TestObject");

class VietHeroesGame:public Lotus::Game
{
public:
	virtual IGameState* getInitialState() const
	{
		//MapState* map=MapFactoryBase::getInstance().createMapFromFile("../Data/Maps/test.map");
		//return map;
		return new DummyState;
	};
protected:
	virtual bool initGraphicManager()
	{
		new GraphicManager;
		bool ret= GraphicManager::getInstance().init(Lotus::Direct3D9, "Viet Heroes", 1024, 768, false);		
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
		return ret;
	}
};

VietHeroesGame game;

int main(int argc,char* argv[])
{
#ifndef _DEBUG
	try
	{
#endif
		if(Lotus::Game::getInstance().init())
			Lotus::Game::getInstance().run();
#ifndef _DEBUG
	}
	catch(Ogre::Exception& e) 
	{
        MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
		throw;
    }
	catch(OIS::Exception& e) 
	{
		MessageBoxA( NULL, e.eText, "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    }
	catch(std::exception& e)
	{
		MessageBoxA( NULL, e.what(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
	}
#endif
	return 0;
}